<?php


namespace App\Transformers\Store;
use App\Models\LiveAnchor;
use App\Models\StoreServiceSpeechcraft;
use App\Transformers\Category\CategoryTransformer;
use App\Transformers\Category\EditTransformer;
use App\Transformers\MerchantRegistersTransformer;
use League\Fractal\TransformerAbstract;

class StoreServiceSpeechcraftTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['storeservice','mer','categories'];

    public function transform(StoreServiceSpeechcraft $data)
    {
        return [
            'id' => $data->id,
            'service_id' =>$data->service_id ?? "",
            'pid' =>$data->pid ?? "",
            'sort' =>$data->sort ?? "",
            'title' =>$data->title ?? "",
            'content' =>$data->content ?? "",
            'mer_id' => $data->mer_id ?? "",
            'category_id' => $data->category_id ?? "",
            'created_at' => $data->created_at ? $data->created_at->format("Y-m-d H:i:s") : '',
            'updated_at' => $data->updated_at ? $data->updated_at->format("Y-m-d H:i:s") : '',
            'category' => $data->categories,
        ];
    }

    /**
     * 可关联的客服的数据
     */
    public function includestoreservice(StoreServiceSpeechcraft $storeServiceSpeechcraftt)
    {
        return $this->item($storeServiceSpeechcraftt->storeservice, new StoreServiceTransformer());

    }

    /**
     *可关联的商户的数据
     */
    public function includemer(StoreServiceSpeechcraft $storeServiceSpeechcraft){
        return $this->item($storeServiceSpeechcraft->mer, new MerchantRegistersTransformer());
        }

     /**
      * 所关联的分类
      */
     public function includecategories(StoreServiceSpeechcraft $storeServiceSpeechcraft){
         return $this->item($storeServiceSpeechcraft->categories,new EditTransformer());
     }

}
